package com.lailai.bizobject;

import com.lailai.metadata.Property;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @Author lgr
 * @Date 2025/9/15
 * @Description 业务对象实体属性
 * @Email 983105834@qq.com
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BizObjectEntityProperty {
    // 属性所属的表名
    private String tableCode;
    // 属性编码（字段key）
    private String code;
    // 显示名称
    private String name;
    // 属性值
    private Object value;
    // 属性定义
    private BizObjectEntityPropertyDefinition bizObjectEntityPropertyDefinition;

    //    private List<ValidationRule> validationRules;
//    private List<MandatoryRule> mandatoryRules;
    public void setPropertyDefinition(BizObjectEntityPropertyDefinition bizObjectEntityPropertyDefinition) {
        this.bizObjectEntityPropertyDefinition = bizObjectEntityPropertyDefinition;
    }

    public static BizObjectEntityProperty of(Object value, Property property) {
        BizObjectEntityProperty bizObjectEntityProperty = new BizObjectEntityProperty();
        bizObjectEntityProperty.setCode(property.getId());
//        bizObjectEntityProperty.setName(property.getName());
        bizObjectEntityProperty.setValue(value);
        bizObjectEntityProperty.setPropertyDefinition(BizObjectEntityPropertyDefinition.of(property));
        return bizObjectEntityProperty;
    }
}
